<?php

namespace App\Models;

class Payments extends Base
{

    /**
     * 取得实物订单所需支付金额等信息
     * @param int $pay_sn
     * @param int $member_id
     * @return array
     */
    protected function getRealOrderInfo($pay_sn, $user_id = null)
    {
        //验证订单信息
        $order_pay_info = OrderPays::where(['pay_sn'=>$pay_sn,'user_id'=>$user_id])->first();
        if (empty($order_pay_info)) {
            return ['state'=>0,'msg'=>'该支付单不存在'];
        }
        $order_pay_info['subject'] = '订单_' . $order_pay_info['pay_sn'];
        $order_pay_info['order_type'] = 'real_order';

        $order_list = Orders::allLists(['pay_sn'=>$pay_sn]);

        //计算本次需要在线支付的订单总金额
        $pay_amount = 0;
        if (!empty($order_list)) {
            foreach ($order_list as $order_info) {
                if ($order_info['order_state'] != 1) {
                    $pay_amount += floatval($order_info['order_amount']);
                }
            }
        }

        $order_pay_info['api_pay_amount'] = $pay_amount;
        $order_pay_info['order_list'] = $order_list;
        return ['state'=>1,'msg'=>'','data'=>$order_pay_info];
    }


}
